@extends('admin.main')

@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>商品列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            @if(session('shop_info'))
                <a class="btn" href="{{urlPlat('single','getScoreGoodsAdd')}}">新 增</a>
                <button class="btn list_sort" url="{{urlPlat($ctr,'getScoreGoodsSort',['shop_id'=>request('shop_id')])}}">排序</button>
                <button class="btn ajax-post" url="{{urlPlat($ctr,'anyChangeScoreGoodsStatus',['method'=>'up',['shop_id'=>request('shop_id')]])}}"
                        target-form="ids">上 架
                </button>
                <button class="btn ajax-post" url="{{urlPlat($ctr,'anyChangeScoreGoodsStatus',['method'=>'down',['shop_id'=>request('shop_id')]])}}"
                        target-form="ids">下 架
                </button>
            @endif
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            @if(plat_identify() == 'admin' && !session('shop_info'))
                <div style="float: left;margin-right: 10px;line-height: 26px;">
                    <select name="shop_id" id="shop_id" style="height: 30px;">
                        <option value="0" @if(request('shop_id') == 0) selected @endif>请选择店铺</option>
                        @if(count($shops))
                            @foreach($shops as $v)
                                <option value="{{$v['id']}}" @if(request('shop_id') == $v['id']) selected @endif>{{$v['shop_name']}}</option>
                            @endforeach
                        @endif
                    </select>
                </div>
            @endif
            <div class="sleft">
                <input type="text" name="keyword" class="search-input" value="{{request('keyword')}}"
                       placeholder="请输入商品名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat($ctr,'getScoreGoods')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                @if(plat_identify() == 'account')<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>@endif
                <th class="">商品图片</th>
                <th class="">商品名称</th>
                <th class="">商品积分</th>
                <th class="">状态</th>
                <th class="">创建时间</th>
                <th class="">更新时间</th>
                @if(plat_identify() == 'account')<th class="">操作</th>@endif
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        @if(plat_identify() == 'account')<td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}"/></td>@endif
                        {{--<td>{{$v['id']}}</td>--}}
                        <td>
                            <img src="/uploads/goods/score/{{$v['id']}}_1_{{$mini}}.{{$ext}}?{{time()}}"/>
                        </td>
                        <td>{{$v['goods_name']}}</td>
                        <td>{{$v['goods_score']}}</td>
                        <td style="color: @if($v['status'] > 0) blue @elseif($v['status'] < 0) red @endif">{{$v['status_text']}}</td>
                        <td><span>{{$v['created_at']}}</span></td>
                        <td><span>{{$v['updated_at']}}</span></td>
                        @if(plat_identify() == 'account')
                            <td>
                                {{--<a href="javascript:;" onclick="showInfo({{$v['id']}})">详情</a>--}}
                                <a title="编辑"
                                   href="{{urlPlat($ctr,'getScoreGoodsEdit',['id'=>$v['id'],'shop_id'=>$v['shop_id']])}}">编辑</a>
                                @if($v['status'] == 1)
                                    <a href="{{urlPlat($ctr,'anyChangeScoreGoodsStatus',['method'=>'down','ids'=>$v['id'],'shop_id'=>$v['shop_id']])}}"
                                       class="ajax-get" style="color:red">下架</a>
                                @else
                                    <a href="{{urlPlat($ctr,'anyChangeScoreGoodsStatus',['method'=>'up','ids'=>$v['id'],'shop_id'=>$v['shop_id']])}}"
                                       class="ajax-get" style="color:blue">上架</a>
                                @endif
                            </td>
                        @endif
                    </tr>
                @endforeach
            @else
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat($ctr,'getScoreGoods',['page'=>$v])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')

    <script type="text/javascript">

        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var shop_id = $("#shop_id").val();
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (shop_id != '' || shop_id != undefined || shop_id != null) {
                query = 'shop_id=' + shop_id + "&" + query;
            }
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function(event){
            if(event.keyCode===13){
                $("#search").click();
            }
        });

        //点击排序
        $('.list_sort').click(function(){
            var url = $(this).attr('url');
            var ids = $('.ids:checked');
            var param = '';
            if(ids.length > 0){
                var str = new Array();
                ids.each(function(){
                    str.push($(this).val());
                });
                param = str.join(',');
            }

            if(url != undefined && url != ''){
                window.location.href = url + '&ids=' + param;
            }
        });
    </script>
@endsection
